﻿#include "UdpCodec_MCUCtrl.h"

#include "MCUCodec.h"
#include "TransmitCodec.h"

UdpCodec_MCUCtrl::UdpCodec_MCUCtrl()
{
  setObjectName(getClassNameFirstLow<UdpCodec_MCUCtrl>());
}

UdpCodec_MCUCtrl::~UdpCodec_MCUCtrl()
{

}

DataPackage_UdpCodec *UdpCodec_MCUCtrl::decode(DataPackage_UdpCodec *dataPackageInfo_Device)
{
  //目前的反馈包没有数据体，只需转发。如果以后有新的改动则需根据具体的数据包类型进行转发操作
  QByteArray data=dataPackageInfo_Device->getData();
  if(data.isEmpty())//如果数据体为空则说明是对MCU操作的确认，直接转发回客户端
    {
      transmitCodec->decode_udp(dataPackageInfo_Device->getDeviceId(),
                                dataPackageInfo_Device->getMsgId(),
                                dataPackageInfo_Device->getPackageType(),
                                data);
      return Q_NULLPTR;
    }
  uchar type=mCUCodec->getType(data);
  if(MCUCodec::Size_MCUCtrlType<=type)//不正常的数据包，丢弃
    {
      return Q_NULLPTR;
    }
  //需要分析的数据

  return Q_NULLPTR;
}

MCUCodec* UdpCodec_MCUCtrl::getMCUCodec()const
{
  return mCUCodec;
}

UdpCodec_MCUCtrl* UdpCodec_MCUCtrl::setMCUCodec(MCUCodec* const mCUCodec)
{
  this->mCUCodec=mCUCodec;
  printInjection(this,mCUCodec);
  return this;
}

TransmitCodec* UdpCodec_MCUCtrl::getTransmitCodec()const
{
  return transmitCodec;
}

UdpCodec_MCUCtrl* UdpCodec_MCUCtrl::setTransmitCodec(TransmitCodec* const mCUCodec)
{
  this->transmitCodec=mCUCodec;
  printInjection(this,mCUCodec);
  return this;
}

void UdpCodec_MCUCtrl::objectAutoInjection(QHash<QString,QObject*>* objMap)
{
  setTransmitCodec(getObjFromMap<TransmitCodec>(objMap));
  setMCUCodec(getObjFromMap<MCUCodec>(objMap));
}
